import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import index from '@/components/index'
import student from '@/components/student'
import teacher from '@/components/teacher'
import defaults from '@/components/default'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    } , {
      path: '/index',
      name: 'index',
      component: index,
      children:[
        {path:'student',component:student},
        {path:'teacher',component:teacher},
      ]
    }
  ]
})

//重写回调方法，解决vue-router在本身页面再次点击同一个路由报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
